package cn.edu.sjtu.se.dslab.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.sjtu.se.dslab.action.bean.PageBean;
import cn.edu.sjtu.se.dslab.component.aadl.AADLTemplate;
import cn.edu.sjtu.se.dslab.dao.IAADLTemplateDao;
import cn.edu.sjtu.se.dslab.exception.DBException;
import cn.edu.sjtu.se.dslab.service.IAADLTemplateService;
import cn.edu.sjtu.se.dslab.util.Const;

@Service("aadlTemplateService")
@Transactional
public class AADLTemplateService implements IAADLTemplateService {
	@Resource(name = "aadlTemplateDao")
	private IAADLTemplateDao aadlTemplateDao;

	@Override
	public boolean addAADLTemplate(AADLTemplate aadlTemplate) {
		// TODO Auto-generated method stub
		aadlTemplateDao.save(aadlTemplate);
		return true;
	}

	@Override
	public AADLTemplate getAADLTemplateById(long id) {
		// TODO Auto-generated method stub
		return aadlTemplateDao.queryById(id);
	}

	@Override
	public AADLTemplate getAADLTemplateByUri(String uri) {
		// TODO Auto-generated method stub
		return aadlTemplateDao.queryByUri(Const.URI_AADL_TEMPLATE+":"+uri);
	}

	@Override
	public boolean updateAADLTemplate(AADLTemplate aadlTemplate) {
		// TODO Auto-generated method stub
		aadlTemplateDao.update(aadlTemplate);
		return true;
	}

	@Override
	public PageBean<AADLTemplate> getPageBean(int pageNo) throws DBException {
		// TODO Auto-generated method stub
		return aadlTemplateDao.queryByPageNum(pageNo);
	}

	@Override
	public PageBean<AADLTemplate> getPageBeanByAttr(int pageNo, String name,
			String description,long groupid) throws DBException {
		// TODO Auto-generated method stub
		return aadlTemplateDao.queryByPageNum(pageNo, name, description,groupid);
	}

	@Override
	public boolean deleteAADLTemplate(AADLTemplate aadlTemplate) {
		// TODO Auto-generated method stub
		return aadlTemplateDao.delete(aadlTemplate);
	}

}
